
<html>
<head>
	<script src="owenge.equation-beta.js" type="text/javascript"></script>
	<script>
		function onComputeClick() {
			var formula = document.getElementById('formula');
			var eq = owenge.equation.parse(formula.value);
			setValue(eq.answer, eq.error);
		}
		
		function onClearClick() {
			var formula = document.getElementById('formula');
			formula.value = '';
			setValue('', '');
		}
		
		function setValue(ans, ex) {
			var result = document.getElementById('result');
			result.innerHTML  = ans;
			
			var error = document.getElementById('error');
			error.innerHTML  = ex;
		}
	</script>
	<style>
		input {
			font-family: tahoma;
			font-size: 1em;
		}
	</style>
</head>
<body>
	<h1>Equation Parser Demo</h1>
	<label>Enter formula:<label><br />
	<input type="text" id="formula" size="50" style="padding:5px; font-size:1.2em;" />
	<input type="button" value="Compute" style="padding:5px; font-size:1.2em;" onclick="onComputeClick()" />
	<input type="button" value="Clear" style="padding:5px; font-size:1.2em;" onclick="onClearClick()" />
	<p>Answer: <span id="result" style="font-weight:bold;text-decoration:underline;color:blue"></span><br />Error: <span id="error" style="color:red"></span></p>
	<hr />
	<h4>Sample Usage:</h4>
	<code>
		var input = '1+2';<br />
		var eq = owenge.equation.parse(input);<br />
		document.writeln(eq.answer);<br />
		document.writeln(eq.error);<br /><br />
		
		// Answer is 3<br /><br />
		
		input = '(((-1+2)*5+-10)/3*2)+100/2/3/4/-5+(90*5)';<br />
		eq = owenge.equation.parse(input);<br /><br />
		
		// Answer is 445.8333333<br /><br />
		
		input = '10+20%*100'; // will be converted to <strong>10+(20/100)*100</strong><br />
		eq = owenge.equation.parse(input);<br /><br />
		
		// Answer is 30<br /><br />
	</code>
</body>
</html>